package com.cee.exception;

import com.cee.common.result.Result;
import com.cee.util.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        log.error("{}",  ExceptionUtil.getFullStackTrace(e));
        log.error("========================== Exception ERROR START ==========================");
        log.error("{}",  ExceptionUtil.getFullStackTrace(e));
        log.error("========================== Exception ERROR END ==========================");
        return Result.fail();
    }

    @ExceptionHandler(CeeException.class)
    @ResponseBody
    public Result error(CeeException e) {
        log.error("{}",  ExceptionUtil.getFullStackTrace(e));
        log.error("========================== ERROR START ==========================");

        log.error("errorInfo:\r\nerorrCode: {}\nerrorMsg: {}", e.getCode(), e.getMessage());
        log.error("{}",  ExceptionUtil.getFullStackTrace(e));

        log.error("========================== ERROR END ==========================");
        return  Result.build(e.getCode(),e.getMessage());
    }
}
